<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>
<head>
<style type="text/css">
	*{
	  margin: 0px;
	  padding: 0px;
	  font-size: 12px;
	}
</style>
</head>
<body class="gray-bg">

<!-- 隐藏域 -->
<input type="hidden" value="${busiId}" id="busiId" name="busiId"/>
<!-- 隐藏域 -->

<div class="container creditbody">
	<div class="iboxtitle">
		<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;业务受理>弃贷表</span>
		<a href="javascript:void(0)"></a>
	</div>
	<form class="form-horizontal m-t" id="commentForm">
		<div class="ibox-content ibox-con">
			<div class="buttonfixed">
				<button type="button" class="btn dpbtn_blue btnaplly" onclick="save();">确定弃贷</button>
			</div>
			<div class="business-padding">
				<%@include file="/jsp/common_yw_with_loan_include.jsp"%>
			</div>
		</div>
	
	    <div class="business-manwife" id="" >弃贷登记</div>
	    <div class="business-padding" id="" >
	        <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
				<tr>
					<td align="right">
						<label class="control-label">弃贷时间：</label>
					</td>
					<td>
						<input id="date_abandon" name="date_abandon" placeholder="请输入时间(必填)" required="required" class="laydate-icon form-control" onclick="laydate()">
					</td>
					
					<td align="right">
						<label class="control-label">弃贷原因：</label>
					</td>
					<td>
						<select id="reason_exit" name="reason_exit" class="select-control">
							&nbsp;
						</select>
					</td>
				</tr>
				<tr>
					<td align="right" valign="top">
						<label class="control-label">弃贷备注：</label>
					</td>
					<td colspan="3">
						<textarea id="remarks" name="remarks" rows="3" cols="" class="form-control"></textarea>
					</td>
				</tr>
			</table>
		  </div>
	  </form>
 </div>
  
<!-- public quote -->
<%@include file="/jsp/comm_js_include.jsp" %>

<!-- layerDate plugin javascript -->
<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script	

<!-- custom js -->
 
<!-- 
   js 
 -->
<script type="text/javascript">																
	$(function(){	
	    $("#commentForm").validate({
	        //重写showErrors
	        showErrors: function (errorMap, errorList) {
	            
	            $.each(errorList, function (i, v) {
	                layer.tips(v.message, v.element, { time: 1500 });
	                return false;
	            });  
	        },
	        /* 失去焦点时验证 */
	        onfocusout: function(element) { $(element).valid(); },
	        /*  键盘抬起不验证 */
	        onkeyup:false,
	    });
	});
	
	$(function(){
		initData();
	});
	
	var initData = function()
	{
		var id = $('#id').val();
		var busiId = $('#busiId').val();
		
		$.dpAjax({
			show:false,
	   		url:'${basePath}/YwShouLiController/getQiDaiYuanYin',
	   		data:{"busiId":busiId},
			success: function(datas){
		 	  if(datas.flag == "100100"){
		 		 
		 		  var d = datas.result;
		 		  
		 		  var objs = '';
		 		  
		 		  for(var key in d)  
		 		  {
		 			 objs += '<option value="'+key+'">'+d[key]+'</option>';
		 		  }
		 		  
		 		  $('#reason_exit').html(objs);
		 		  
		 		  var d = datas.ywLoanAbandon;
		 		  if(d && null != d)
		 		  {
		 			  $('#date_abandon').val(d.dateAbandon);
		 			  $('#remarks').val(d.remarks);
		 			  
		 			 var t = document.getElementById("reason_exit");
		 			 for(var i=0;i<t.length;i++)
		 			 {
		 				 if(t[i].value == d.reasonExit)
		 				 {
		 					t[i].selected = true;
		 					break;
		 				 }
		 			 }
		 		  }
		 		  
				  return;
			  }
			  if(datas.flag == "100200"){
				  alert(JSON.stringify(datas));
	              return;
	          }
			  layer.msg(datas.message, {icon: 2});
			}
	   	});
	}
	
	//弃贷执行
	var save = function()
	{
		var validstatus = $("#commentForm").valid();
		if(validstatus){
			var busiId = $('#busiId').val();
			var date_abandon = $('#date_abandon').val();
			var reason_exit = $('#reason_exit').val();
			var remarks = $('#remarks').val();
			
			//询问框
			layer.confirm('弃贷就绪，是否确认本次操作？操作人：<span style="color:#BD1723;">${current_user_key.uname}</span>', {
			  btn: ['确定','取消'] //按钮
			}, function(){
				layer.closeAll();
				$.dpAjax({
			   		url:'${basePath}/YwShouLiController/ywShouLiQiDaiBiao',
			   		data:{
			   			"busiId":busiId,
			   			"cusId":'${current_user_key.id}',
			   			"dateAbandon":date_abandon,
			   			"reasonExit":reason_exit,
			   			"remarks":remarks,
			   			"id":busiId,
			   			"busiStatus":"9820"
			   		},
					success: function(datas){
				 	  if(datas.flag == "100100")
				 	  {
				 		  layer.msg("弃贷执行成功！", {icon: 6});
				 		  setTimeout(function () {
				 			 window.location.href = "${basePath}/web/ywShouLi/abandonLendingList.jsp";
				 		  }, 1000);
						  return;
					  }
					  if(datas.flag == "100200")
					  {
						  alert(JSON.stringify(datas));
			              return;
			          }
					  layer.msg(datas.message, {icon: 2});
					}
			   	});
				
			}, function(){
				layer.msg("已取消本次操作！", {icon: 6});
			});
		}	
	}
</script>
</body>
</html>
